<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript字符串及其方法</title>
</head>
<body>
    <h1>JavaScript字符串及其方法</h1>
    <script>
        let str1='单引号定义';
        document.writeln(str1+"<br>");
        let str2="双引号定义";
        document.writeln(str2+"<br>");
        let str3="\"转义符号\\\"";
        document.writeln(str3+"<br>");
        let str4="字符串连接符+"+"def";
        document.writeln(str4+"<br>");
        let str5="\xA9";
        document.writeln(str5+"<br>");
        let str6="\u00A9";//UTF-8字符串定义
        document.writeln(str6+"<br>");
        let str7=new String("字符串对象String");
        document.writeln(str7+"<br>");

        //字符串的方法:
        localStorage("12,34,56".split(","));
        document.writeln("abc中国def".indexOf("中"));
        document.writeln("字符串拼接".concat("abc"));
        document.write("<br>");
        
        //数值<--> 字符串
        let n=3;
        document.writeln(typeof n.toString());
        document.write("<br>");

        document.writeln(parseFloat("3.01abc"));
        document.writeln(parseFloat("1abc"));
        document.write("<br>");

        //模板字符串 反引号`` 支持${} 解析
        let name="张三";
        let age=19;
        document.writeln("姓名"+name+","+"年龄:"+age);
        document.write("<br>");
        document.writeln(`姓名:${name},年龄:${age}`);
        document.write("<br>");
        let str8=`
        多行文本1
        多行文本2
        `;
        document.writeln(str8);
        document.write("<br>");

        //字符串长度，以及数组的形式访问
        let a="中123";
        document.writeln(a.length+"<br>");
        document.writeln(a[0]+"<br>");
    </script>
</body>
</html>